package top.byteio.common.message.factory;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import top.byteio.common.message.config.MessageProperties;
import top.byteio.common.message.eunms.MessagerType;
import top.byteio.common.message.exception.MessagerNotFound;
import top.byteio.common.message.messager.MailMessager;
import top.byteio.common.message.messager.NoticeMessager;
import top.byteio.common.message.messager.SmsAliyunMessager;
import top.byteio.common.message.messager.SmsTencentMessager;
import top.byteio.common.message.pojo.MessagerProperty;

import java.util.Map;

import static top.byteio.common.message.eunms.MessagerType.*;

@Slf4j
@RequiredArgsConstructor
public class NoticeMessagerFactory {

    private final MessageProperties messageProperties;


    public NoticeMessager getMessager(MessagerType messagerType) {
        Map<MessagerType, MessagerProperty> properties = messageProperties.getProperties();
        return switch (messagerType) {
             case MAIL -> MailMessager.getInstance(properties.get(MAIL));
             case SMS_ALIYUN -> SmsAliyunMessager.getInstance(properties.get(SMS_ALIYUN));
             case SMS_TENCENT -> SmsTencentMessager.getInstance(properties.get(SMS_TENCENT));
             default -> {
                 log.error("未找到该消息发送器:MessagerType: {} ", messagerType);
                 throw new MessagerNotFound("未找到该消息发送器:MessagerType: " + messagerType, null);
             }
         };
    }
}
